package com.wc.alorithm_luogu.P1807;


import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/5/22 17:07
 * @description https://www.luogu.com.cn/problem/P1827
 * [USACO3.4] 美国血统 American Heritage
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String inorderStr = sc.nextLine();

        String preOrderStr = sc.nextLine();

        new Main().work(inorderStr, preOrderStr);
    }

    public void work(String inorderStr, String preOrderStr) {
        if (preOrderStr.isEmpty()) {
            return;
        }
        char root = preOrderStr.charAt(0);

        int k = inorderStr.indexOf(root);

//        preOrderStr = preOrderStr.replace(root + "", "");

        work(inorderStr.substring(0, k), preOrderStr.substring(1, k + 1));
        work(inorderStr.substring(k + 1), preOrderStr.substring(k + 1));

        System.out.print(root);
    }
}
